home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / alv.sun / alv.lha / src / scr2ras.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-08  |  3.9 KB  |  161 lines

  1. /*
  2.  * Modified and renamed src2ras, 1988 by Phill Everson for inclusion into ALV
  3.  * toolkit.
  4.  * 
  5.  * dumpregion - dump a region of a sun screen in rasterfile format. Copyright
  6.  * Richard Tobin 1987.  You may freely copy, modify and distribute this
  7.  * program in source form provided this comment remains intact.
  8.  * 
  9.  * Richard Tobin,                    JANET: R.Tobin@uk.ac.ed           AI
  10.  * Applications Institute,        ARPA:  R.Tobin%uk.ac.ed@nss.cs.ucl.ac.uk
  11.  * Edinburgh University.             UUCP:  ...!ukc!ed.ac.uk!R.Tobin
  12.  */
  13.  
  14. #include "defs.h"
  15. #include <sys/file.h>
  16. #include <suntool/fullscreen.h>
  17.  
  18. har           *progname;
  19.  
  20. hort           nwdata[] = {
  21. #include "../images/cursors/stretchNW.cursor"
  22. };
  23. pr_static(nwpixrect, 16, 16, 1, nwdata);
  24.  
  25. hort           sedata[] = {
  26. #include "../images/cursors/stretchSE.cursor"
  27. };
  28. pr_static(sepixrect, 16, 16, 1, sedata);
  29.  
  30. ect            rect = {0, 0, 0, 0};
  31.  
  32. olormap_t     *colormap = NULL;
  33.  
  34. #ifdef STANDALONE
  35. ain(argc, argv, envp)
  36. #else
  37. cr2ras_main(argc, argv, envp)
  38. #endif
  39.     int             argc;
  40.     char          **argv;
  41.     char          **envp;
  42. {
  43.     int             wfd;
  44.     struct fullscreen *fs;
  45.     Event           event;
  46.     Pixwin         *pw;
  47.     int             left, right, top, bottom, temp;
  48.     Window          win;
  49.     double          w;
  50.  
  51.     progname = strsave(argv[0]);
  52.     parse_profile(&argc, argv, envp);
  53.  
  54.     while ((gc = getopt(argc, argv, " ")) != EOF)
  55.         switch (gc) {
  56.         case '?':
  57.             errflag++;
  58.             break;
  59.         }
  60.  
  61.     if (errflag)
  62.         error((char *) 0, "Usage: %s: [outfile]\n", progname);
  63.  
  64.     for (stream = 0; optind < argc; stream++, optind++)
  65.         if (stream ==0 && strcmp(argv[optind], "-") != 0)
  66.             if (freopen(argv[optind],"w" ,stdout) == NULL)
  67.                 error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
  68.  
  69.     win = window_create(0, FRAME,
  70.                 FRAME_OPEN_RECT, &rect,
  71.                 WIN_CONSUME_PICK_EVENTS,
  72.                 LOC_MOVE, WIN_MOUSE_BUTTONS, 0,
  73.                 0);
  74.  
  75.     wfd = (int) window_get(win, WIN_FD);
  76.     fs = fullscreen_init(wfd);
  77.     pw = fs->fs_pixwin;
  78.  
  79.     window_set(win,
  80.            WIN_CURSOR, cursor_create(CURSOR_IMAGE, &nwpixrect,
  81.                          CURSOR_XHOT, 0, CURSOR_YHOT, 0,
  82.                          0),
  83.            0);
  84.  
  85.     while (window_read_event(win, &event) == -1 ||
  86.            !event_is_down(&event) ||
  87.            !event_is_button(&event));
  88.  
  89.     right = left = event_x(&event);
  90.     bottom = top = event_y(&event);
  91.  
  92.     window_set(win,
  93.            WIN_CURSOR, cursor_create(CURSOR_IMAGE, &sepixrect,
  94.                        CURSOR_XHOT, 15, CURSOR_YHOT, 15,
  95.                          0),
  96.            0);
  97.  
  98.     drawbox(pw, left, top, right, bottom);
  99.  
  100.     while (window_read_event(win, &event) == -1 ||
  101.            !event_is_up(&event) ||
  102.            !event_is_button(&event)) {
  103.         drawbox(pw, left, top, right, bottom);
  104.         right = event_x(&event);
  105.         bottom = event_y(&event);
  106.         drawbox(pw, left, top, right, bottom);
  107.     }
  108.  
  109.     drawbox(pw, left, top, right, bottom);
  110.     fullscreen_destroy(fs);
  111.  
  112.     window_set(win, FRAME_NO_CONFIRM, TRUE, 0);
  113.     window_destroy(win);
  114.  
  115.     if (right < left) {
  116.         temp = right;
  117.         right = left;
  118.         left = temp;
  119.     }
  120.     if (bottom < top) {
  121.         temp = bottom;
  122.         bottom = top;
  123.         top = temp;
  124.     }
  125.     dumpregion(left, top, right, bottom);
  126.  
  127.     return 0;
  128. }
  129.  
  130. rawbox(pw, left, top, right, bottom)
  131.     Pixwin         *pw;
  132.     int             left, top, right, bottom;
  133. {
  134.     fullscreen_pw_vector(pw, left, top, right, top, PIX_NOT(PIX_DST), 0);
  135.     fullscreen_pw_vector(pw, right, top, right, bottom, PIX_NOT(PIX_DST), 0);
  136.     fullscreen_pw_vector(pw, right, bottom, left, bottom, PIX_NOT(PIX_DST), 0);
  137.     fullscreen_pw_vector(pw, left, bottom, left, top, PIX_NOT(PIX_DST), 0);
  138. }
  139.  
  140. umpregion(left, top, right, bottom)
  141.     int             left, top, right, bottom;
  142. {
  143.     Pixrect        *pr, *pr2, *pr3;
  144.     int             width, height;
  145.  
  146.  
  147.     pr = pr_open("/dev/fb");
  148.     if (pr == 0)
  149.         error("Can't open /dev/fb");
  150.  
  151.     width = (((right - left + 1) / 8) * 8);
  152.     height = (((bottom - top + 1) / 4) * 4);
  153.     pr2 = pr_region(pr, left, top, width, height);
  154.     pr3 = pr_region(pr2, 0, 0, width, height);
  155.  
  156.     if (pr_dump(pr3, stdout, colormap, RT_STANDARD, 1) != 0) {
  157.         perror("pr_dump");
  158.         exit(1);
  159.     }
  160. }
  161.